var a = getApp();

Page({
    data: {
        language: "",
        recharge_value: void 0,
        recharge_id: void 0,
        usable: 0,
        ratio: 0,
        arrival_count: 0,
        coin_name: ""
    },
    onLoad: function(a) {
        this.getUsable();
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getUsable: function() {
        var t = this, e = a.getNetAddresss("plugin.coin.Frontend.Controllers.page.index");
        a._getNetWork({
            url: e,
            success: function(a) {
                1 === a.data.result ? (t.setData({
                    usable: a.data.data.usable,
                    coin_name: a.data.data.coin_name,
                    ratio: a.data.data.transfer_proportion
                }), wx.setNavigationBarTitle({
                    title: a.data.data.coin_name ? a.data.data.coin_name + "转账" : "转账"
                })) : wx.showToast({
                    title: a.data.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getBalance: function() {
        var t = this;
        if (this.data.recharge_value) {
            var e = a.getNetAddresss("plugin.coin.Frontend.Modules.Coin.Controllers.transfer.index");
            e += "&recipient=" + this.data.recharge_id, e += "&change_value=" + this.data.recharge_value, 
            a._getNetWork({
                url: e,
                success: function(a) {
                    1 === a.data.result ? (wx.showToast({
                        title: a.data.msg,
                        icon: "none"
                    }), t.setData({
                        recharge_value: "",
                        recharge_search: ""
                    }), setTimeout(function() {
                        t.getUsable(), wx.navigateBack({
                            delta: 1
                        });
                    }, 1e3)) : wx.showToast({
                        title: a.data.msg,
                        icon: "none"
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        } else wx.showToast({
            title: "转账值不能为空",
            icon: "none"
        });
    },
    onChange: function(a) {
        if (console.log(a.detail, "值"), !/^[\+\-]?\d*?\.?\d*?$/.test(a.detail)) return wx.showToast({
            title: "只能输入数字",
            icon: "none"
        }), void this.setData({
            recharge_id: ""
        });
        this.setData({
            recharge_id: a.detail
        });
    },
    onChange2: function(a) {
        this.setData({
            recharge_value: a.detail
        });
        var t = this.data.recharge_value - this.data.recharge_value * (this.data.ratio / 100);
        t = t.toString(), this.setData({
            arrival_count: t.replace(/([0-9]+.[0-9]{2})[0-9]*/, "$1")
        });
    }
});